#include <ESP8266WiFi.h>

const char* ssid = "HONOR";

const char* password = "22222222";

int ledPin = 2;

WiFiServer server(80);

void setup()

{

Serial.begin(115200);

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

Serial.print("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, password);


while (WiFi.status() != WL_CONNECTED)

{

delay(100);

Serial.print(".");

}

Serial.println("");

Serial.println("Connected to WiFi");

Serial.print("IP: "); Serial.println(WiFi.localIP());


server.begin();

}

void loop()
{

WiFiClient client = server.available();

if (!client) {

return;

}
while(!client.available()){

}

String request = client.readStringUntil('\r');

Serial.println(request);

client.flush();

int value = LOW;

if (request.indexOf("/LED=ON") != -1)

{

digitalWrite(ledPin, HIGH);

value = HIGH;

}

if (request.indexOf("/LED=OFF") != -1)

{

digitalWrite(ledPin, LOW);

value = LOW;

}

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println(""); // do not forget this one

client.println("<!DOCTYPE HTML>");

client.println("<html>");

client.print("status: ");

if(value == HIGH)
{
client.print("ON");
}
else
{
client.print("OFF");
}

client.println("<br><br>");
client.println("<a href=\"/LED=ON\"><img src='https://bpic.588ku.com/element_pic/19/03/20/82cff97d3141163a9f1dd1f8c365b80d.jpg' /></a>");
client.println("<a href=\"/LED=OFF\"><img src='https://tse4-mm.cn.bing.net/th/id/OIP-C.gjzAN2y7fxmqDJOUGZ7DBAAAAA?w=163&h=180&c=7&r=0&o=5&dpr=1.4&pid=1.7' /></a>");
client.println("</html>");
Serial.println("");

}